<?php

class Video_Plugin_Service_Embedly
{
	function getName()
	{
		return 'embedly';
	}

	function getVideoInfo($link)
	{
		$return = array();

		$q = array(
			'url' => $link,
			'maxwidth' => 500
		);

		$apiLink = "http://api.embed.ly/1/oembed?" . http_build_query($q, NULL, '&');

		$curl = new Nuo_Curl();

		$response = $curl -> send($apiLink);

		$data = json_decode($response, 1);

		if (!$data or !isset($data['type']) or $data['type'] != 'video')
		{
			return NULL;
		}
		
		$return['title'] = $data['title'];
		$return['source_id'] = $code;
		
		// there is no duration info
		$return['duration'] = 0;
		$return['extra'] = $data['html'];
		$return['description'] = $data['description'];
		$return['thumbnail_large'] = $data['thumbnail_url'];
		
		return $return;

	}

	function getEmbedCode($item, $params)
	{
		return $item->extra;
		$sourceId = $item -> source_id;
		$view = 1;
		$string = <<<THESTRING
<object width=":width" height=":height">
<param name="allowfullscreen" value="true"/>
<param name="allowscriptaccess" value="always"/>
<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=:clipId&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" />
<embed src="http://vimeo.com/moogaloop.swf?clip_id=:clipId&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1&amp;autoplay=:autoplay" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width=":width" height=":height" wmode="transparent"/>
<param name="wmode" value="transparent" />
</object>
THESTRING;

		return strtr($string, array(
			':width' => '425',
			':height' => '344',
			':clipId' => $item -> source_id,
			':autoplay' => 0
		));
	}

}
